package com.ruoyi.project.crm.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.crm.domain.LinkmanSource;
import com.ruoyi.project.crm.service.ILinkmanSourceService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 来源渠道Controller
 * 
 * @author ruoyi
 * @date 2020-06-19
 */
@RestController
@RequestMapping("/crm/linkmanSource")
public class LinkmanSourceController extends BaseController
{
    @Autowired
    private ILinkmanSourceService linkmanSourceService;

    /**
     * 查询来源渠道列表
     */
    @PreAuthorize("@ss.hasPermi('crm:linkmanSource:list')")
    @GetMapping("/list")
    public TableDataInfo list(LinkmanSource linkmanSource)
    {
        startPage();
        List<LinkmanSource> list = linkmanSourceService.selectLinkmanSourceList(linkmanSource);
        return getDataTable(list);
    }

    /**
     * 导出来源渠道列表
     */
    @PreAuthorize("@ss.hasPermi('crm:linkmanSource:export')")
    @Log(title = "来源渠道", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(LinkmanSource linkmanSource)
    {
        List<LinkmanSource> list = linkmanSourceService.selectLinkmanSourceList(linkmanSource);
        ExcelUtil<LinkmanSource> util = new ExcelUtil<LinkmanSource>(LinkmanSource.class);
        return util.exportExcel(list, "linkmanSource");
    }

    /**
     * 获取来源渠道详细信息
     */
    @PreAuthorize("@ss.hasPermi('crm:linkmanSource:query')")
    @GetMapping(value = "/{linkmanSourceId}")
    public AjaxResult getInfo(@PathVariable("linkmanSourceId") Long linkmanSourceId)
    {
        return AjaxResult.success(linkmanSourceService.selectLinkmanSourceById(linkmanSourceId));
    }

    /**
     * 新增来源渠道
     */
    @PreAuthorize("@ss.hasPermi('crm:linkmanSource:add')")
    @Log(title = "来源渠道", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LinkmanSource linkmanSource)
    {
        return toAjax(linkmanSourceService.insertLinkmanSource(linkmanSource));
    }

    /**
     * 修改来源渠道
     */
    @PreAuthorize("@ss.hasPermi('crm:linkmanSource:edit')")
    @Log(title = "来源渠道", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LinkmanSource linkmanSource)
    {
        return toAjax(linkmanSourceService.updateLinkmanSource(linkmanSource));
    }

    /**
     * 删除来源渠道
     */
    @PreAuthorize("@ss.hasPermi('crm:linkmanSource:remove')")
    @Log(title = "来源渠道", businessType = BusinessType.DELETE)
	@DeleteMapping("/{linkmanSourceIds}")
    public AjaxResult remove(@PathVariable Long[] linkmanSourceIds)
    {
        return toAjax(linkmanSourceService.deleteLinkmanSourceByIds(linkmanSourceIds));
    }
}
